<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head th:include="header">
<style type="text/css">
#targetPage body {
	overflow-y: scroll;
}
</style>
</head>
<script type="text/javascript" th:inline="javascript">
	function changepage(result) {
		if (result == "map") {
			$("#targetPage").load("page.html?jsp=lable/amap");
		}
		$("#targetPage").load(result + ".html");
	}
	function changeDetails(result) {
		$("#targetPage").load(result);
	}
	
	function getCookie(name)
	{
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg))
	return unescape(arr[2]);
	else
	return null;
	}
</script>
<body>
	<div th:remove="all">模版页面</div>
	<div id="lableViews">
		<div th:replace="menu :: facilityDiv"></div>
		<div th:replace="menu :: header"></div>
		<div th:replace="menu :: leftNav"></div>
		<div th:replace="menu :: title(${session.userName?:'未知'})"></div>
<!-- 		<div th:replace="menu :: title(getCookie('userName'))"></div> -->
		<iframe class="rightMain" id="targetPage" src="lable.html"
			name="targetPage" border="0" frameborder="0" scrolling="no"></iframe>

		<!-- 		<div class="rightMain" id="targetPage"> -->

		<!-- 		</div> -->
	</div>
</body>
<script type="text/javascript" th:inline="javascript"
	th:with="basePath=${'ws://'+#request.serverName+':'+#request.serverPort+#request.contextPath}">
onload = function(){
	$(".leftNav a").eq(0).css("background","rgb(26, 99, 190)");
	$(".leftNav a").eq(0).click(function(){
		$("#targetPage").attr("src","lable.html")
		$(".leftNav a").eq(0).css("background","rgb(26, 99, 190)").siblings().css("background","#169BD5")
	})
	$(".leftNav a").eq(1).click(function(){
		$("#targetPage").attr("src","addLable.html")
		$(".leftNav a").eq(1).css("background","rgb(26, 99, 190)").siblings().css("background","#169BD5")
	})
	$(".leftNav a").eq(2).click(function(){
		$("#targetPage").attr("src","router.html")
		$(".leftNav a").eq(2).css("background","rgb(26, 99, 190)").siblings().css("background","#169BD5")
	})
	$(".leftNav a").eq(3).click(function(){
		$("#targetPage").attr("src","page.html?jsp=lable/amap")
		$(".leftNav a").eq(3).css("background","rgb(26, 99, 190)").siblings().css("background","#169BD5")
	})
	$(".leftNav a").eq(4).click(function(){
		$("#targetPage").attr("src","user.html")
		$(".leftNav a").eq(4).css("background","rgb(26, 99, 190)").siblings().css("background","#169BD5")
	})
	$(".leftNav a").eq(5).click(function(){
		$("#targetPage").attr("src","statistics.html")
		$(".leftNav a").eq(5).css("background","rgb(26, 99, 190)").siblings().css("background","#169BD5")
	})
	$(".leftNav a").eq(6).click(function(){
		$("#targetPage").attr("src","warning.html")
		$(".leftNav a").eq(6).css("background","rgb(26, 99, 190)").siblings().css("background","#169BD5")
	})
	$("#titleRight a").eq(1).click(function(){
		$("#targetPage").attr("src","user.html")
		$(".leftNav a").eq(4).css("background", "rgb(26, 99, 190)")
							.siblings().css("background", "#169BD5")
	})
// 	$("#titleRight a:nth-child(1)").click(function(){
// 			$("#targetPage").attr("src","user.html")
// 	});
}
$(document).ready(function(){
	$("#warningNum").html(0);
	 var wsurl = [[${basePath +'/webSocket/global.ws?'}]];
		 ws = new WebSocket(wsurl);
	ws.onopen = function() {
		console.log('websocket 打开成功');
	}; 
	 //当收到服务端的消息时
	ws.onmessage = function(result) {
	    //result.data 是服务端发来的数据
	    if(result.data=="WebSocket:connected OK!"){
	    }else{
	        var result=JSON.parse(result.data);
	        if(typeof(result.data)=="object"){
	        	if (result.hasOwnProperty('desc') && result['desc'] == 'COUNT-STAT') {
	        		for (var k in result.data) {
			        	var num = parseInt($("#warningNum").html());
			        	var count = num + parseInt(result.data[k]);
			        	console.log("打印："+count);
			        	$("#warningNum").html(count);
	        		}
	        	}
	        }else{
	        	
	        }
	    }
	// 当websocket关闭时
	//ws.onclose = function() {
	 //   alert("websocket 连接关闭");
	//};
	// 当出现错误时
	ws.onerror = function(e) {
	    console.log("出现错误"+e);
	}
}
});

var myArr = new Array();
var aa = {
    "alertEvent":{"temperature":"90","battery":"100.0"},"createTime":"2017-06-02 	17:43:16","id":"bc1013c2-5fb5-6b96-507e-a0959082b4ae","tagSn":"13999999"
}
var bb = {
    "alertEvent":{"temperature":"90","battery":"100.0"},"createTime":"2017-06-02 	17:43:16","id":"bc1013c2-5fb5-6b96-507e-a0959082b4ae","tagSn":"13999999"
}
myArr.push(aa);
myArr.push(bb);
localStorage.setItem("alert",JSON.stringify(myArr));
</script>
<script th:src="${ctx+'/resources/js/user/loginout.js'}"
	type="text/javascript"></script>
<footer th:include="footer"></footer>
</html>
